var webClientContext = null;
var PCMSGLIST = [];

function isMacI4tools() {
    return (
        navigator.userAgent.match(/i4Tools/i) &&
        navigator.userAgent.match(/mac/i)
    );
}

function zz_send(msg) {
    if (isMacI4tools()) {
        if (typeof window['qt'] !== 'undefined' && !webClientContext) {
            new QWebChannel(window['qt'].webChannelTransport, function (channel) {
                webClientContext = channel.objects.webClient;
            });
        }
        if (webClientContext) {
            webClientContext.someFoo(msg);
        } else {
            // 未初始化成功时，将消息添加到消息队列，等待初始化成功后再发送
            PCMSGLIST.push(msg);
        }
    } else {
        console.log('window发送消息', msg);
        window['i4Client'].sendMessage(msg);
    }
}

(function aa() {
    setInterval(function () {
        if (webClientContext && PCMSGLIST.length) {
            zz_send(PCMSGLIST.pop());
        }
    }, 250);
})();
